package java51.demo18;

public class Dog implements Comparable<Dog> {
	private String name;
	private String color;
	private int age;

	public Dog() {
	}

	@Override
	// 比较规则
	public int compareTo(Dog o) {

		return this.age - o.age;
		// return this.name.compareTo(o.name);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Dog(String name, String color, int age) {
		super();
		this.name = name;
		this.color = color;
		this.age = age;
	}

	@Override
	public String toString() {
		return "狗 [name=" + name + ", color=" + color + ", age=" + age + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Dog other = (Dog) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	// @Override
	// public int hashCode() {
	// return name.hashCode();
	// }
	//
	// @Override
	// // 自定义比较的规则，用name作为比较的依据
	// public boolean equals(Object obj) {
	// if (obj.getClass() != Dog.class) {
	// return false;
	// }
	// Dog d = (Dog) obj;
	// return this.name.equals(d.name);
	// }
}
